package djboom.materials.display.page.work3 {
	import djboom.materials.Work;
	import djboom.materials.core.BitmapDataCore;
	import djboom.materials.display.elements.HotSpot;
	import djboom.materials.display.elements.RoundedButton;
	import djboom.materials.display.elements.WindowDevice;
	import djboom.materials.display.page.Page;
	import djboom.materials.events.PageEvent;
	import djboom.materials.events.WindowEvent;

	import org.casalib.display.CasaBitmap;

	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;

	/**
	 * .
	 * <br>
	 * 
	 * @author DJ BooM 
	 * @since 06.04.2010
	 * 
	 */

	public class Page1 extends Page {

		// ----------------------------------------------------------------------------
		// Константы класса.
		// ----------------------------------------------------------------------------

		// ----------------------------------------------------------------------------
		// Свойства класса.
		// ----------------------------------------------------------------------------

		private var _textBitmap:CasaBitmap;
		private var _simpleButton:RoundedButton;
		private var _flaskLeChatelierHS:HotSpot;
		private var _window:WindowDevice;

		// ----------------------------------------------------------------------------
		// Конструктор.
		// ----------------------------------------------------------------------------

		public function Page1() {
			super();
		}	 

		// ----------------------------------------------------------------------------
		// Методы класса.
		// ----------------------------------------------------------------------------

		private function changePage(event:MouseEvent):void {
			var pageEvent:PageEvent = new PageEvent(PageEvent.CHANGE);
			pageEvent.pageName = Page.WORK_3_PAGE_2;            
			dispatchEvent(pageEvent);
		}

		private function showDevice(event:MouseEvent):void {
			 lockPage();
            
            _window = new WindowDevice();
            _window.addEventListener(WindowEvent.CLOSE, closeWindow);
            _window.init("Прибор Ле-Шателье");
            addChild(_window);
		}
		

        private function closeWindow(event:WindowEvent):void {
            unlockPage();
            
            if (_window != null) {
                _window.destroy();
                _window = null;
            }
        }

		// ----------------------------------------------------------------------------
		// Публичные методы.
		// ----------------------------------------------------------------------------

		override public function init():void {
			// Создаем заголовок страницы.
			createTitleWork(WORK3_NAME, 3);
            
			_textBitmap = new CasaBitmap(BitmapDataCore.getBitmapData(BitmapDataCore.WORK3_PAGE1_TEXT));
			_textBitmap.x = 38;
			_textBitmap.y = 100;
			addChild(_textBitmap);
			
			_flaskLeChatelierHS = new HotSpot();
			_flaskLeChatelierHS.drawRect(new Rectangle(0, 0, 200, 30));
			_flaskLeChatelierHS.x = 496;			_flaskLeChatelierHS.y = 328;
			_flaskLeChatelierHS.addEventListener(MouseEvent.CLICK, showDevice);
			addChild(_flaskLeChatelierHS);
            
			_simpleButton = new RoundedButton("Продолжить");
			_simpleButton.x = Work.WIDTH * 0.5 - _simpleButton.width * 0.5;
			_simpleButton.y = Work.HEIGHT - 118;
			_simpleButton.addEventListener(MouseEvent.CLICK, changePage);
			addChild(_simpleButton);
		}

		
		
		override protected function clearPage(event:Event):void {
			super.clearPage(event);
			
			_simpleButton.destroy();
			_simpleButton = null;
            
			_textBitmap.destroy();
			_textBitmap = null;
		}
        
		// ----------------------------------------------------------------------------
        // Публичные свойства.
        // ----------------------------------------------------------------------------
	}
}
